package com.yanqu.road.server.cmd.activity.selectlottery;

import com.yanqu.road.entity.activity.selectlottery.data.SelectLotteryNoticeData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SelectLotteryProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.selectlottery.CrossSelectLotteryActivity;
import com.yanqu.road.server.manager.activity.selectlottery.CrossSelectLotteryMgr;
import com.yanqu.road.server.manager.activity.selectlottery.pb.CrossSelectLotteryPb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C2_SELECT_LOTTERY_NOTICE_LIST, desc = "通用自选抽奖-公告LIST")
public class CrossSelectLotteryNoticeListCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SelectLotteryProto.SelectLotteryGetNoticeListReqMsg reqMsg = SelectLotteryProto.SelectLotteryGetNoticeListReqMsg.parseFrom(packet.getBytes());
        SelectLotteryProto.SelectLotteryGetNoticeListRespMsg.Builder respMsg = SelectLotteryProto.SelectLotteryGetNoticeListRespMsg.newBuilder();
        CrossSelectLotteryActivity activity = CrossSelectLotteryMgr.getActivity(reqMsg.getActivityId());
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SELECT_LOTTERY_GET_NOTICE_LIST, respMsg));
            return;
        }
        List<SelectLotteryNoticeData> noticeList = activity.getNoticeList();
        for (SelectLotteryNoticeData notice : noticeList) {
            respMsg.addNotices(CrossSelectLotteryPb.buildSelectLotteryNoticeData(notice));
        }
        respMsg.setRet(0);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SELECT_LOTTERY_GET_NOTICE_LIST, respMsg));
    }

    @Override
    public void sendData() {

    }
}
